//找一个字符串中一个字串出现的次数
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_SIZE 100

char * my_strchr(char *s,int n)
{
    while(*s != '\0')
    {
        if(*s == n)
        {
            return s;
        }
        s++;
    }
    return NULL;
}

int count_sub_str(char *sub,char *src)
{
    int count = 0;
    int s_len = strlen(sub);

    char *result = strchr(src,*sub);//遍历src
    while(result != NULL)
    {
        if(strncmp(sub,result,s_len) == 0)
        {
            count++;
            result = result + s_len;
        }
        else
        {
            result++;
            result = strchr(result,*sub);
            //src++;
        }
        
    }
    return count;
}

int main(int argc,char *argv[])
{
    char *sub;
    char src[MAX_SIZE];

    printf("Please input src:\n");
    scanf("%s",src);

    sub = (char *)malloc(sizeof(char) * MAX_SIZE);

    if(sub == NULL)
    {
        printf("malloc sub is error\n");
        exit(1);
    }

    printf("Please input sub:\n");
    scanf("%s",sub);

    int count = count_sub_str(sub,src);

    printf("sub str count = %d\n",count);
    return 0;
}